<?php 
$this->display(tpl('head',true)); 
if($edit['bold']){
	$bold='checked';
}
if($nid>1){
	$display="style='display:none'";
}
?>

<style>
	.color{
		width: 70px;
	}
</style>
<script src="/public/global/js/colpick.js" type="text/javascript" charset="utf-8"></script>
<form class="layui-form" method="post" action="">
	<div class="w-100 left bcf ">
		<div class="layui-form-item mt10">
			<label class="layui-form-label">所属栏目</label>
			<div class="layui-input-block">
				<select name="post[cid]" lay-filter="ciddb">
				<option value="">请选择要发布到的栏目</option>\r\n
				<?php
				foreach($allcidDB AS $row){
					$p_dis="";
					$setting=unserialize($row['setting'])['power'][C('mydb.groupid')];
					if((!$setting['add'] && C('mydb.groupid') !='3') || $row['type'] !==0){
						$p_dis='disabled';
					}
					$selected="";
					if($row['cid']==$cid && !$p_dis){
						$selected=" selected";
					}
				 ?>
				<option type="{{$row['type']}}" value="<?php echo $row['cid'] ?>" <?php echo $selected; ?> <?php echo $p_dis ?>><?php echo $row['levels']; echo $row['name'] ?></option>\r\n
				<?php } ?>
				</select>
			</div>
		</div>
		<div class="layui-form-item mt10">
			<label class="layui-form-label">标题</label>
			<div class="layui-input-block">
				<input name="post[title]" value="<?php echo $edit['title'] ?>"  lay-verify="title" placeholder="请输入标题" class="layui-input my-input" type="text">
			</div>
		</div>
		<div class="layui-form-item mt10">
			<label class="layui-form-label">关键字</label>
			<div class="layui-input-block">
				<input name="post[keyword]"  class="layui-input my-input" type="text" value="<?php echo $edit['keyword'] ?>">
				<p>作为相关文章的索引,如多个用空格隔开</p>
			</div>
		</div>
		<div class="layui-form-item mt10">
			<label class="layui-form-label">作者</label>
			<div class="layui-input-block">
				<input name="post[author]" class="layui-input" type="text" value="<?php echo $edit['author'] ?>">
			</div>
		</div>
		<div class="layui-form-item mt10">
			<label class="layui-form-label">来源</label>
			<div class="layui-input-block">
				<input name="post[source]" class="layui-input" type="text" value="<?php echo $edit['source']?>">
			</div>
		</div>
		<div class="layui-form-item mt10">
			<label class="layui-form-label">来源网址</label>
			<div class="layui-input-block">
				<input name="post[source_url]" class="layui-input" type="text" value="<?php echo $edit['source_url']?>">
			</div>
		</div>
		<div class="layui-form-item mt10">
			<label class="layui-form-label">缩略图</label>
			<div class="layui-input-block">
				<input name="post[thumb]" id="thumb" class="layui-input  my-input" type="text" value="<?php echo $edit['thumb'] ?>">
				<button type="button" class="layui-btn layui-btn-normal" id="select_pic">选择图片上传</button>
			</div>
		</div>
	</div>
	<?php if($Custom_Model_Template){ ?>
	<div class="w-100 left bcf mt10">
		<?php echo $Custom_Model_Template ?>
	</div>
	<?php } ?>
	<style>
		.content .layui-form-label{
			width: 100%;
			height: 25px;
			text-align: left;
			line-height: 25px;
		}
		.content .layui-input-block {
			width: 100%;
			float: left;
			margin-left: 0;
			min-height: initial;
		}
	</style>
	<?php
		$i=0;
		$num=count((array)$cont_query);
		if($num >1){
	?>
	<div class="layui-form-item w-100 left mt10 center page bcf" style="height: 45px;line-height: 45px;">
		<?php 
			foreach($cont_query AS $row){
				$i++;
		?>
		<a href="javascript:void(0);" onclick="return content('<?php echo $row['nid'] ?>',this);"> 第<?php echo $i ?>页</a>
		<?php } ?>
		<script>
			var content_data=<?php echo json_encode($cont_query); ?>;
		</script>
	</div>
	<?php } ?>
	<div class="w-100 left bcf mt10">
		<div class="layui-form-item content mt10">
			<label class="layui-form-label">文章内容:</label>
			<div class="layui-input-block">
				<textarea name="post[content]" style="height:300px; width: 100%; z-index: 1;" id="content" placeholder="请输入内容" ><?php echo $cont_query['0']['content'] ?></textarea>
				<script type="text/javascript">
					var ue = UE.getEditor('content',{
						zIndex : 900,
						autoHeightEnabled:false,
				       	serverUrl: "/user/index/plugin/ueditor/setting/ueditor_config/",
				      	toolbars: [<?php echo json_encode(C('UEDITOR_CONFIG.function')) ;?>]
					});
				</script>
			</div>
		</div>
	</div>
	<div class="w-100 left bcf mt10">
		<div class="layui-form-item mt10 center page">
			<input type="hidden" name="post[aid]" value="<?php echo $edit['aid'] ?>" />
			<input type="hidden" id="nid" name="post[nid]" value="<?php echo $cont_query['0']['nid'] ?>" />
			<input type="hidden" id="mid" name="post[mid]" value="<?php echo $mid ?>" />
			<input type="hidden" name="post[step]" value="post" />
			<button class="layui-btn" lay-submit="" lay-filter="post">立即提交</button>
		</div>
	</div>
	<script>
		var _this='';
		function content(nid,THIS){
			if(_this){
				_this.style.backgroundColor='';
				_this.style.color ='';
				_this.style.fontWeight ='';
			}
			_this=THIS;
			for(var i=0;i<content_data.length;i++){
				if(content_data[i].nid==nid){
					ue.setContent(content_data[i].content);
					$("#nid").val(nid);
				}
			}
			console.log(THIS);
			THIS.style.backgroundColor='red';
			THIS.style.color ='#fff';
			THIS.style.fontWeight ='bold';
		}
	</script>
</div>
</form>
<script>

layui.config({
	version: '<?php echo NOWTIME ?>'
});
layui.use(['upload','form','layer','element','laydate'], function(){
  	var $ = layui.jquery
  	,element = layui.element
  	,upload = layui.upload;
   	var $ = layui.jquery, layer = layui.layer;
	var form = layui.form;
	form.on('select(ciddb)', function(data){
		var type=data.elem.selectedOptions[0].attributes.type.value;
		if(type !=0){
			$('.layui-btn').attr("disabled",true);
			alert("只有栏目才可以发布内容，请重新选择");
			return false;
		}else if(data.value > 0){
			window.location.href='/user/articles/add/cid/'+data.value;
			$('.layui-btn').attr("disabled",false); 
		}
	});
	var laydate = layui.laydate;
	laydate.render({
		elem: '#posttime',
		type: 'datetime'
	});
	form.verify({
	    title: function(value){
		    if(value.length < 5){
		        return '标题至少得5个字符';
		    }
	    }
  	});


	
	
	//选完文件后不自动上传
	upload.render({
	    elem: '#select_pic',
	    url: '/user/upfile/up/thumb/1/json/true/',
	    auto: true,
	    bindAction: '#star_upload',
	    before: function(obj){
	    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
	    	loading = layer.load();
	    },
	    done: function(res, index, upload){
	    	layer.close(loading);
		    if(res.code !=0){
		    	layer.msg(res.text);
		    }else{
		      	$('#thumb').val(res.url); 
		    }
		    delete files[index]; //删除对应的文件
	    }
	});
});
</script>
<?php $this->display(tpl('foot',true)); ?>
